package com.gw.booking.service;

import com.gw.booking.entity.Logs;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class LogService {
	@Autowired
	SessionFactory sessionFactory;
	@Autowired
	UserService userService;

	
	public void txAddLog(Logs.LogType operateType, Integer userId, String content) {
		Session session = sessionFactory.getCurrentSession();
		
		Logs logs = new Logs();
		logs.setOperateType(operateType.name());
		logs.setUserName(userService.getUserName(session, userId));
		logs.setOperateContent(content);
		logs.setCreatedAt(new Date());
		
		session.save(logs);
		session.flush();
	}
}
